package com.ideal.manage.esms.compoment;

import com.ideal.manage.esms.service.system.UnitCellDataScanService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;


/**
 * @author Allen
 */
@Component
public class UnitCellDataScan {
    private Logger logger = LoggerFactory.getLogger(UnitCellDataScan.class);
    @Autowired
    private UnitCellDataScanService unitCellDataScanService;
    @Value("${config.task.unitcell.enable}")
    private Boolean unitcellTaskEnable;

    /**
     * 每小时的第00,15,30,45分钟开始扫描入库
     */
    @Scheduled(cron = "0 00,15,30,45 * * * ?")
    public void scanBattery() {
        if (unitcellTaskEnable) {
            try {
                unitCellDataScanService.getScanBattery();
                logger.info("扫描es中的电池单体成功");
            } catch (ParseException e) {
                logger.error(e.getMessage(), e);
            }
        } else {
            logger.debug("UnitCellDataScan任务展厅");
        }
    }

}
